﻿//*** Guidance generated code ***//
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;

using ProjectBase.Core;

namespace ProjectBase.Mvc
{
    /// <summary>
    ///     html &lt;OPTION&gt; element.
    ///     Should (can) be used only for a Select element
    /// </summary>
    public class Option : ContentControl<ICoreModel, Option>, IOption, ISelectChild
    {
        #region members
        Literal _literal = new Literal();
        #endregion members

        #region constructor
        public Option(string text = null, bool doLocalize = false, string cssClassName = null)
            : base(cssClassName)
        {
            Controls.Add(_literal);
            _literal.SetText(text, doLocalize);
        }
        #endregion constructor

        #region Set
        public virtual Option SetText(string text, bool doLocalize = false)
        {
            Literal.Text = text;
            Literal.DoLocalize = doLocalize;
            return this;
        }

        public virtual Option SetType(string typeName)
        {
            Type = typeName;
            return this;
        }

        public virtual Option SetValue(string value)
        {
            Value = value;
            return this;
        }

        public virtual Option SetSelected(bool isSelected)
        {
            if (isSelected)
            {
                Selected = Attr.Selected;
            }
            else
            {
                Attributes.Remove(Attr.Selected);
            }
            return this;
        }

        public virtual Option SetDisabled(bool isDisabled)
        {
            if (isDisabled)
            {
                Attributes.Remove(Attr.Disabled);
            }
            else
            {
                Disabled = Attr.Disabled;
            }
            return this;
        }
        #endregion Set

        #region properties
        public virtual bool HasText
        {
            get { return Literal.Text.IsNotEmpty(); }
        }

        protected override string TagName
        {
            get { return Tag.Option; }
        }

        protected virtual Literal Literal
        {
            get { return _literal; }
            set { _literal = value; }
        }

        public virtual string Type
        {
            get { return GetAttribute(Attr.Type); }
            set { SetAttribute(Attr.Type, value); }
        }

        public virtual string Disabled
        {
            get { return GetAttribute(Attr.Disabled); }
            set { SetAttribute(Attr.Disabled, value); }
        }

        public virtual string Selected
        {
            get { return GetAttribute(Attr.Selected); }
            set { SetAttribute(Attr.Selected, value); }
        }

        public virtual string Value
        {
            get { return GetAttribute(Attr.Value); }
            set { SetAttribute(Attr.Value, value); }
        }
        #endregion properties
    }
}